/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Helper;

import ButtonBeans.ControllerElement;
import ButtonBeans.RoundButtonBean;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * @author luc0
 */
public class ControllerValidator {

    private static ControllerValidator instance;

    private ControllerValidator(){

    }
    public static ControllerValidator getInstance(){
        if(instance == null){
            instance = new ControllerValidator();
        }
        return instance;
    }

    public boolean isControllerValid(List<ControllerElement> controllerList){
        boolean isControllerValid = true;
        Set<Integer> buttonIdSet = new HashSet<Integer>();

        for(ControllerElement element: controllerList){
            buttonIdSet.add(new Integer(element.getButtonId()));
           if(element.getLx()<0 || element.getLx()>480){
               isControllerValid = false;
           } else if(element.getLy()<0 || element.getLy()>320){
               isControllerValid = false;
           }  else if(element.getHeight() < 1){
               isControllerValid = false;
           }else if(element.getWidth() < 1 ){
               if(element instanceof RoundButtonBean){

               }else{
                    isControllerValid = false;
               }
              
           }else if(element.isRepeatsPresses() && element.getTimeBetweenPresses()<1){
               isControllerValid = false;
           }
        }
         if(buttonIdSet.size() != controllerList.size()){
               isControllerValid = false;
          } else if(controllerList == null || controllerList.isEmpty()){
              isControllerValid = false;
          }
        return isControllerValid;
    }
}
